<%@ page contentType="text/html; charset=UTF-8"%>
<%@include file="../../common/taglibs.jsp"%>

<script type="text/javascript">
    $(document).ready(function () {
        /**
         * 进行校核绑定
         */
        $('#contractEditForm input').each(function () {
            if ($(this).attr('required') || $(this).attr('validType')) {
                $(this).validatebox();
            }
        });

        $('#formContractbutton').click(function() {
            if (!$("#contractEditForm").form('validate')) {
                return;
            }

            //提交表单
            saveAjaxData("${ctx}/contract/save.do", "contractEditForm", "contractWindow", "contractGrid");
        });

        $("#editTable tr:odd").addClass("cssline_1");

        $('#project').combobox({
            url:'${ctx}/project/getProjects.do',
            valueField:'id',
            panelHeight:'auto',
            onSelect:function(record){
                setWordCout(record.wordCount);
            },
            textField:'name'
        });

    });

    function setWordCout(count){
        $("#wordCount").val(count);
        calcAmount();
    }


    function calcAmount(){
        var count =  parseInt( $("#wordCount").val());
        var price =  parseFloat( $("#price").val());
        var professionalFee =  parseFloat( $("#professionalFee").val());
        var urgentFee =  parseFloat( $("#urgentFee").val());
        var typesettingFee =  parseFloat($("#typesettingFee").val());
        var totalAmount = 0.00;
        if(count&&price){
            totalAmount = (count * price/1000);
        }
        if(professionalFee){
            totalAmount += professionalFee;
        }
        if(urgentFee){
            totalAmount += urgentFee;
        }
        if(typesettingFee){
            totalAmount += typesettingFee;
        }
        $("#moneyAmount").val(totalAmount.toFixed(2));
        $("#advancePayment").val((totalAmount/2).toFixed(2));
    }

</script>

<div>
    <form:form id="contractEditForm" name="contractEditForm" modelAttribute="bean" action="${ctx}/contract/save.do" method="post">
        <input type="hidden" name="id" value="${bean.id}" />
        <div>
            <table border="0" cellspacing="1" width="100%" id="editTable">

                <tr class="cssline">
                    <td  class="csslabel">
                        项目:
                    </td>
                    <td  class="container">
                        <input type="text"
                            <%--class="easyui-combobox"--%>
                               name="project"
                               id="project"
                               url="${ctx}/project/getProjects.do"
                               valueField="id"
                               textField="name"

                               select="getWords()"
                               value="${bean.project.id}"/>&nbsp;
                    </td>
                </tr>
                <tr class="cssline">
                    <td  class="csslabel">
                        合同名称:
                    </td>
                    <td  class="container">
                        <input type="text" name="name" value="${bean.name}"  required="true" class="input_table" maxlength="50"/>&nbsp;
                    </td>
                </tr>
                <tr class="cssline">
                    <td  class="csslabel">
                        合同代码:
                    </td>
                    <td  class="container">
                        <input type="text" name="code" value="${bean.code}"  required="true" class="input_table" maxlength="50"/>&nbsp;
                    </td>
                </tr>
                <tr class="cssline">
                    <td  class="csslabel">
                        甲方:
                    </td>
                    <td  class="container">
                        <input  type="text" name="firstPartyName" value="${bean.firstParty.name}" class="input_table" id="firstPartyName" disabled="true"/>
                        <input  type="hidden" name="firstParty" value="${bean.firstParty.id}" id="firstParty" />
                        <img src="${ctx}/skin/icons/edit_add.png" id="popTree" onclick="new PopTree({url:'${ctx}/contract/getSecond.do',targetId:'firstParty',targetValueId:'firstPartyName',onlyLeaf:true});">
                    </td>
                </tr>
                <tr class="cssline">
                    <td  class="csslabel">
                        乙方:
                    </td>
                    <td  class="container">
                        <input  type="text" name="secondPartyName" value="${bean.secondParty.name}" class="input_table" id="secondPartyName" disabled="true"/>
                        <input  type="hidden" name="secondParty" value="${bean.secondParty.id}" id="secondParty" />
                        <img src="${ctx}/skin/icons/edit_add.png"  onclick="new PopTree({url:'${ctx}/contract/getFirst.do',targetId:'secondParty',targetValueId:'secondPartyName',onlyLeaf:true});">
                    </td>
                </tr>
                <tr class="cssline">
                    <td  class="csslabel">
                        甲方签订日期:
                    </td>
                    <td  class="container">
                        <input type="text" name="fisrtSignDate" class="Wdate" value="${bean.fisrtSignDate}" onFocus="WdatePicker({isShowClear:false,readOnly:true})" style="width:140px"/>&nbsp;
                    </td>
                </tr>
                <tr class="cssline">
                    <td  class="csslabel">
                        乙方签订日期:
                    </td>
                    <td  class="container">
                        <input type="text" name="secondSignDate" class="Wdate" value="${bean.secondSignDate}" onFocus="WdatePicker({isShowClear:false,readOnly:true})" style="width:140px"/>&nbsp;

                    </td>
                </tr>
                <tr class="cssline">
                    <td  class="csslabel">
                        翻译价格(元/千字符):
                    </td>
                    <td  class="container">
                        <input type="text" name="price" id="price" class="input_table" value="${bean.price}" style="width:140px"  required="true" validType="number(0)" onblur="calcAmount()"/>&nbsp;
                    </td>
                </tr>
                <tr class="cssline">
                    <td  class="csslabel">
                        翻译字数:
                    </td>
                    <td  class="container">
                        <input type="text" name="wordCount" id="wordCount" class="input_table" value="${bean.project.wordCount}" style="width:140px" readonly="true"/>&nbsp;
                    </td>
                </tr>
                <tr class="cssline">
                    <td  class="csslabel">
                        专业技术费(元):
                    </td>
                    <td  class="container">
                        <input type="text" name="professionalFee" id="professionalFee" class="input_table"  value="${bean.professionalFee}"  style="width:140px" validType="number(2)" onblur="calcAmount()"/>&nbsp;
                    </td>
                </tr>
                <tr class="cssline">
                    <td  class="csslabel">
                        加急费(元):
                    </td>
                    <td  class="container">
                        <input type="text" name="urgentFee" id="urgentFee" class="input_table" value="${bean.urgentFee}" validType="number(2)" style="width:140px" onblur="calcAmount()"/>&nbsp;
                    </td>
                </tr>
                <tr class="cssline">
                    <td  class="csslabel">
                        排版费(元):
                    </td>
                    <td  class="container">
                        <input type="text" name="typesettingFee" id="typesettingFee" class="input_table" value="${bean.typesettingFee}"  style="width:140px" validType="number(2)" onblur="calcAmount()"/>&nbsp;
                    </td>
                </tr>
                <tr class="cssline">
                    <td  class="csslabel">
                        总金额:
                    </td>
                    <td  class="container">
                        <input type="text" name="moneyAmount" id="moneyAmount" class="input_table" value="${bean.moneyAmount}"  style="width:140px" validType="number(2)"/>&nbsp;
                    </td>
                </tr>
                <tr class="cssline">
                    <td  class="csslabel">
                        预付款(元):
                    </td>
                    <td  class="container">
                        <input type="text" name="advancePayment" id="advancePayment" class="input_table" value="${bean.advancePayment}"  style="width:140px" validType="number(2)"/>&nbsp;
                    </td>
                </tr>
                <tr class="cssline">
                    <td  class="csslabel">
                        是否生效:
                    </td>
                    <td  class="container">
                        <input type="checkbox" name="isValid"  ${bean.isValid?"checked":""} />&nbsp;
                    </td>
                </tr>
                <tr class="cssline">
                    <td  class="csslabel">
                        备注:
                    </td>
                    <td  class="container">
                        <textarea type="text" name="remark"  cols="55" rows="4" >${bean.remark}</textarea>&nbsp;
                    </td>
                </tr>
                <tr>
                    <td colspan="2" valign="middle" align="center">
                        <input type="button" id="formContractbutton" value="确定" class="btn_Ok">&nbsp;
                        <input type="button" value="取消" class="btn_Del" onclick="closeWindow('contractWindow')">
                    </td>
                </tr>
            </table>

        </div>
    </form:form>
</div>